layui.use(['table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    /**
     * Dispatch Order Management
     */
    var TransportDispatch = {
        tableId: "transportDispatchTable"
    };

    /**
     * Initialize table columns
     */
    TransportDispatch.initColumn = function () {
        return [[
            {field: 'getUnit', sort: true, title: 'Receiving Unit', style:'background-color: #dbf1e1;font-weight: 600;'},
            {field: 'getLocation', sort: true, title: 'Receiving Address', style:'background-color: #dbf1e1;font-weight: 600;'},
            {field: 'customerOrder', sort: true, title: 'Customer Order No.', style:'background-color: #dbf1e1;font-weight: 600;'},
            {field: 'goodsName', sort: true, title: 'Product Name', style:'background-color: #dbf1e1;font-weight: 600;', totalRowText: 'Total: '},
            {field: 'transportPutvolume', sort: true, title: 'Volume', totalRow: true, style:'font-weight: 600;'},
            {field: 'num', sort: true, title: 'Quantity', totalRow: true, style:'font-weight: 600;'},
            {field: 'tooDeployVolume', sort: true, title: 'Configured Volume', totalRow: true, style:'font-weight: 600;'},
            {field: 'tooDeployNum', sort: true, title: 'Configured Quantity', totalRow: true, style:'font-weight: 600;'},
        ]];
    };

    TransportDispatch.search = function () {
        var queryData = {};
        queryData['customerOrder'] = $("#customerOrder").val();
        queryData['goodsName'] = $("#goodsName").val();
        table.reload(TransportDispatch.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };

	function GetUrlByParamName(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var URL =  decodeURI(window.location.search);
        var r = URL.substr(1).match(reg);
        if(r!=null){
            //decodeURI() function can decode URI encoded by encodeURI() function
            return  decodeURI(r[2]);
        };
        return null;
    };

    // Render table
    var tableResult = table.render({
        elem: '#' + TransportDispatch.tableId,
        url: Feng.ctxPath + '/orderTransportDispatch/listOrder?carnumbger='+GetUrlByParamName("carnumbger"),
        page: false,
        limit: 1000,
        height: "full-60",
        totalRow: true,
        toolbar: '#toolbarDemo', //Enable header toolbar and bind left template
        cellMinWidth: 100,
        cols: TransportDispatch.initColumn()
    });

    // Search button click event
    $('#btnSearch').click(function () {
        TransportDispatch.search();
    });
});
